<template>
	<view class="Global">
		<!-- 背景图片铺满 -->
		<!-- <image class="imagepage" src="/static/background@2x.png" mode=""></image> -->
		<bgImage></bgImage>
		<!-- <view class="personnel" :style="{'height':tarbarHeight+'px'}">
			<image @click="backOnClick" src="../../../static/logo.png" class="backImg" mode=""></image>
			<text class="title">{{personnelInfo}}</text>
		</view> -->

		<MyNav :title="title" bgColor="" :backIcon="isback"></MyNav>

		<view class="updateContent">

			<view class="updateName">
				<view class="updateNameTitle">
					<text class="title1">编号</text>
					<text class="title2">*</text>
				</view>
				<input @input="onInputAccount" class="title3" type="text" :value="addSizeManagerData.templateCode"
					placeholder-class="title3" placeholder="请输入" />
			</view>

			<view class="line"></view>

			<view class="updateName">
				<view class="updateNameTitle">
					<text class="title1">分类名称</text>
					<text class="title2">*</text>
				</view>
				<input @input="onInputPass" class="title3" type="text" value="" :value="addSizeManagerData.templateName"
					placeholder-class="title3" placeholder="请输入" />
			</view>



		</view>


		<view class="loginContent">

			<button @click="addClick()" style="color:#ffffff" class="login" type="default">{{login}}</button>
		</view>


	</view>
</template>

<script>
	import MyNav from '@/components/customnavbar.vue'
	import stringUtil from '@/pages/common/stringUtil.js';
	import bgImage from '@/components/backgroundImage.vue'
	import {
		addProcessTemplateManager
	} from '@/pages/api/api.js'

	export default {
		components: {
			MyNav,
			bgImage
		},
		data() {
			return {
				title: '新增',
				isback: true,

				personnelInfo: '新增',
				tops: 0,
				height: 0,
				tarbarHeight: 0,
				login: '确认',

				addSizeManagerData: {
					colorName: "",
					remark: "", //备注
					storeId: '', //工厂/门店ID
					tenantId: '', //租户ID
					templateName: '', //工序名称
					templateCode: '', //编码
				},

				// 数据对象
				updateManagerData: {},

			}
		},
		onLoad: function(option) {
			let item = JSON.parse(decodeURIComponent(option.item));
			this.updateManagerData = item

			if (Object.keys(this.updateManagerData).length !== 0) { 
				
				this.addSizeManagerData.templateCode = this.updateManagerData.templateCode
				this.addSizeManagerData.templateName = this.updateManagerData.templateName
			}
		},
		methods: {
			// 获取编号输入框的值
			onInputAccount(e) {
				this.addSizeManagerData.templateCode = e.detail.value
			},
			// 获取尺寸名称框输入的值
			onInputPass(e) {
				this.addSizeManagerData.templateName = e.detail.value
			},

			backOnClick() {
				uni.navigateBack({
					delta: 1
				});
				console.log('点击返回');
			},


			addClick() {
				const app = getApp();
				this.addSizeManagerData.storeId = app.globalData.storeId
				this.addSizeManagerData.tenantId = app.globalData.tenantId


				if (stringUtil.isEmpty(this.addSizeManagerData.templateCode) ||
					stringUtil.isEmpty(this.addSizeManagerData
						.templateName)) {
					return
				}
				// console.log('获取全局信息', this.addSizeManagerData);
				// 新增
				addProcessTemplateManager(this.addSizeManagerData).then((res) => {
					// console.log('新增数据', res);

					if (res.code == 200) {
						// 表示添加成功 则返回上一页
						let pages = getCurrentPages();
						let prevPage = pages[pages.length - 2]; //上一个页面
						//直接调用上一个页面的setData()方法，把数据存到上一个页面中去
						prevPage.setData({
							isRefresh: 1
						})
						this.backOnClick()

					}
					// 显示提示信息
					uni.showToast({
						title: res.msg,
						icon: 'none'
					});

				}).catch((err) => {
					console.log('新增失败', err);
				});

			}



		},
		onReady() {
			// 获取标题栏和状态栏高度
			uni.getSystemInfo({
				success: (e) => {
					this.tops = e.statusBarHeight;
					let custom = uni.getMenuButtonBoundingClientRect();
					this.height = custom.height + (custom.top - e.statusBarHeight) * 2;
					this.tarbarHeight = this.tops + this.height;
				}
			})

		}
	}
</script>

<style>
	.loginContent {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width: 750rpx;


	}

	.login {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 20rpx;
		width: 550rpx;
		height: 110rpx;

		border-radius: 30rpx;
		font-weight: 400;
		font-size: 36rpx;
		color: #FFFFFF;
		text-align: center;
		font-weight: bold;

		margin-top: 60rpx;
		background: linear-gradient(90deg, #45A8FF, #0AE1C6);

	}

	.line {
		width: 100%;
		height: 1rpx;
		background: #F9FCFF;



	}

	.title1 {
		font-size: 24rpx;
		color: #333333;

	}

	.title3 {
		font-size: 24rpx;
		color: #333333;
		margin-right: 30rpx;
		width: 100rpx;

	}

	.title2 {
		font-size: 24rpx;
		color: red;

	}

	.updateNameTitle {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-left: 30rpx;
	}

	.updateName {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;

		width: 100%;
		height: 50%;
	}


	.updateContent {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		width: 690rpx;
		height: 240rpx;
		background: #FFFFFF;
		border-radius: 30rpx 30rpx 30rpx 30rpx;
		margin-top: 40rpx;
		margin-left: 30rpx;
	}




	.imagepage {

		background-size: cover;
		background-repeat: no-repeat;
		background-position: center center;
		position: absolute;
		z-index: -1;
		left: 0;
		right: 0;
		bottom: 0;
		right: 0;
		width: 100%;
		height: 100%;
	}
</style>